package edu.dublbo.commons.util;

import org.apache.commons.codec.digest.DigestUtils;

public class MD5Util {
    public static String md5(String src) {
        return DigestUtils.md5Hex(src);
    }

    public static String encrypt(String s, String salt) {
        String str = salt.charAt(0) + salt.charAt(2) + s + salt.charAt(5) + salt.charAt(4);
        return md5(str);
    }

    public static String encrypt(String s) {
        return encrypt(s, SALT);
    }

    public static final String SALT = "1a2b3c4d";

    public static String inputPassToBackendPass(String inputPass) {
//        String str = SALT.charAt(0) + SALT.charAt(2)
//                + inputPass
//                + SALT.charAt(5) + SALT.charAt(4);
        return md5(inputPass);
    }

    public static String backendPassToDBPass(String backendPass, String salt) {
        String str = salt.charAt(0) + salt.charAt(2) + backendPass + salt.charAt(5) + salt.charAt(4);
        return md5(str);
    }

    public static String inputPassToDBPass(String inputPass, String salt) {
        return backendPassToDBPass(inputPassToBackendPass(inputPass), salt);
    }

}
